package com.smart.community.region.vo;

import com.smart.community.commons.enums.SystemStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 楼栋视图对象
 * 
 * @author Wu.Liang
 * @since 2024-12-21
 */
@Data
@Schema(description = "楼栋视图对象")
public class BuildingVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "楼栋ID")
    private Long id;

    @Schema(description = "楼栋编号")
    private String buildingNo;

    @Schema(description = "楼栋名称")
    private String buildingName;

    @Schema(description = "所属社区ID")
    private Long communityId;

    @Schema(description = "所属社区名称")
    private String communityName;



    @Schema(description = "楼栋类型：存储中文建筑类型名称，如住宅楼、商业楼、办公楼、综合楼")
    private String buildingType;

    @Schema(description = "楼栋类型文本")
    private String buildingTypeText;

    @Schema(description = "楼栋类型（根据楼层数判断）")
    private String buildingTypeByFloor;

    @Schema(description = "结构类型：1-框架，2-剪力墙，3-砖混，4-钢结构")
    private Integer structureType;

    @Schema(description = "结构类型文本")
    private String structureTypeText;

    @Schema(description = "楼层数")
    private Integer floorCount;

    @Schema(description = "地下层数")
    private Integer undergroundFloor;

    @Schema(description = "单元数")
    private Integer unitCount;

    @Schema(description = "房户数量")
    private Integer householdCount;

    @Schema(description = "每层户数")
    private Integer unitsPerFloor;

    @Schema(description = "是否有电梯：0-无，1-有")
    private Integer hasElevator;

    @Schema(description = "电梯状态文本")
    private String elevatorStatusText;

    @Schema(description = "电梯数量")
    private Integer elevatorCount;

    @Schema(description = "建成年份")
    private Integer buildYear;

    @Schema(description = "楼龄")
    private Integer buildingAge;

    @Schema(description = "竣工日期")
    private LocalDate completionDate;

    @Schema(description = "建筑面积（平方米）")
    private BigDecimal area;

    @Schema(description = "占地面积（平方米）")
    private BigDecimal landArea;

    @Schema(description = "建筑高度（米）")
    private BigDecimal buildingHeight;

    @Schema(description = "详细地址")
    private String address;

    @Schema(description = "纬度")
    private BigDecimal latitude;

    @Schema(description = "经度")
    private BigDecimal longitude;

    @Schema(description = "楼栋管理员ID")
    private Long managerId;

    @Schema(description = "楼栋管理员姓名")
    private String managerName;

    @Schema(description = "维护公司")
    private String maintenanceCompany;

    @Schema(description = "配套设施（JSON格式）")
    private String facilities;

    @Schema(description = "楼栋图片（JSON数组）")
    private String images;

    @Schema(description = "状态：0-禁用，1-启用")
    private Integer status;

    @Schema(description = "状态文本")
    private String statusText;

    @Schema(description = "排序字段")
    private Integer sortOrder;

    @Schema(description = "入住率（%）")
    private BigDecimal occupancyRate;

    @Schema(description = "平均每层房户数")
    private Integer averageHouseholdPerFloor;

    @Schema(description = "备注")
    private String remark;

    @Schema(description = "创建人ID")
    private Long createBy;

    @Schema(description = "创建人姓名")
    private String createByName;

    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    @Schema(description = "更新人ID")
    private Long updateBy;

    @Schema(description = "更新人姓名")
    private String updateByName;

    @Schema(description = "更新时间")
    private LocalDateTime updateTime;

    // ==================== 业务方法 ====================

    /**
     * 获取状态文本
     */
    public String getStatusText() {
        if (status == null) {
            return "未知";
        }
        return SystemStatusEnum.isEnabled(status) ? "启用" : "禁用";
    }

    /**
     * 获取楼栋类型文本
     */
    public String getBuildingTypeText() {
        if (buildingType == null) {
            return "未知";
        }
        return buildingType;
    }

    /**
     * 获取结构类型文本
     */
    public String getStructureTypeText() {
        if (structureType == null) {
            return "未知";
        }
        switch (structureType) {
            case 1:
                return "框架";
            case 2:
                return "剪力墙";
            case 3:
                return "砖混";
            case 4:
                return "钢结构";
            default:
                return "未知";
        }
    }

    /**
     * 获取电梯状态文本
     */
    public String getElevatorStatusText() {
        if (hasElevator == null) {
            return "未知";
        }
        return hasElevator == 1 ? "有电梯" : "无电梯";
    }

    /**
     * 获取楼栋类型（根据楼层数判断）
     */
    public String getBuildingTypeByFloor() {
        if (floorCount == null || floorCount == 0) {
            return null;
        }
        if (floorCount <= 6) {
            return "多层住宅";
        } else if (floorCount <= 18) {
            return "小高层";
        } else if (floorCount <= 33) {
            return "高层住宅";
        } else {
            return "超高层";
        }
    }

    /**
     * 计算楼龄
     */
    public Integer getBuildingAge() {
        if (buildYear == null) {
            return null;
        }
        return LocalDateTime.now().getYear() - buildYear;
    }

    /**
     * 计算平均每层房户数
     */
    public Integer getAverageHouseholdPerFloor() {
        if (floorCount == null || floorCount == 0) {
            return 0;
        }
        if (householdCount == null) {
            return 0;
        }
        return householdCount / floorCount;
    }
} 